<template>
  <div class="header">
    <div class="header-abs" v-show='showAbs'>
      <router-link tag='div' to='/'  class="iconfont">
        &#xe624;
      </router-link>
    </div>
    <div class="header-fixed"
         v-show='!showAbs'
         :style='styleOpacity'
    >
      <router-link tag='div' to='/'  class="iconfont header-fixed-back">
        &#xe624;
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      showAbs: true,
      styleOpacity: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      console.log(document.documentElement.scrollTop)
      const top = document.documentElement.scrollTop
      if (top > 0) {
        this.showAbs = false
        let opacity = top / 60
        opacity = opacity > 1 ? 1 : opacity
        this.styleOpacity.opacity = opacity
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.header
  position: absolute
  z-index: 10
.header-abs
  position: absolute
  top: .2rem
  left: .2rem
  width: .7rem
  height: .7rem
  line-height: .7rem
  border-radius: .35rem
  text-align: center
  color: #fff
  background: rgba(0, 0, 0, 0.8)
.header-fixed
  position: fixed
  left: 0
  top: 0
  right: 0
  height: $headerHeight
  line-height: $headerHeight
  color: #fff
  background: $bgcolor
  text-align: center
  .header-fixed-back
    position: absolute
    left: .3rem
    height: $headerHeight
</style>
